/*
    32. Write a C programming to find the repeated character in a given string. 
    Test Data :
    Input a string: w3resource
    Expected Output:

    Input a string: The first repetitive character in w3resource is: r
*/

#include <stdio.h>
#include <stdlib.h>

char* getstr(char *str)
{
    char ch;
    char *p = str;
    while((ch = getchar()) != '\n'){
        *p++ = ch;
    }
    *p = '\0';
    return str;
}

int getstrlen(char *str)
{
    int len = 0;
    char *p = str;
    while(*p != '\0'){
        len++;
        p++;
    }
    len++; // '\0'
    return len;
}

char findfirstrept(char *str)
{
    char *p = str;
    char curch;
    int i, cnt = 0;
    while(*p){
        for(i = 0; i < cnt; i++){
            if(curch == *(str + i))
                return *(str + i);
        } 
        cnt++; 
        p++;      
        curch = *p;
    }
    return 0;
}

int main(void)
{
    char *str = malloc(1024);
    printf("Input a string : ");
    getstr(str);
    printf("The first repetitive character in %s is: %c", str, findfirstrept(str));

    return 0;
}